﻿using System.Collections.Generic;
using System.Linq;
using WCF.Common.DAL;
namespace WCF.Common
{
    public static class ConfigDataBuffer
    {
        public static List<RelationRoleService> RelationRoleServices { get; set; }
        public static List<RelationUserRole> RelationUserRoles { get; set; }
        public static List<RelationRoleApp> RelationRoleApps { get; set; }
        public static List<AppObject> Apps { get; set; }
        public static List<Parameters> Parameters { get; set; }
        public static List<RoleObject> Roles { get; set; }
        public static List<UserObject> Users { get; set; }
        public static List<ServiceObject> Services { get; set; }

        static ConfigDataBuffer()
        {
            if (RelationUserRoles == null)
                RefreshBuffer();
        }

        public static void RefreshBuffer()
        {
            RelationUserRoles = new RelationUserRoleDAL().Gets();
            RelationRoleApps = new RelationRoleAppDAL().Gets();
            RelationRoleServices = new RelationRoleServiceDAL().Gets();
            Apps = new AppObjectDAL().Gets();
            Services = new ServiceObjectDAL().Gets();
            Parameters = new QuickDeveloperDBDataContext().Parameters.ToList();
        }

        public static string GetParameter(string key)
        {
            string result = string.Empty;
            if (Parameters.Any(p => p.Key == key))
            {
                result = Parameters.First(p => p.Key == key).Value;
            }
            return result;
        }
    }
}